package com.jsgt.greekfire.repository

import com.jsgt.greekfire.bean.CurrencyDescribe
import com.jsgt.greekfire.bean.DealsBean
import com.jsgt.greekfire.bean.DepthBean
import com.jsgt.greekfire.common.http.ResponseData
import com.jsgt.greekfire.common.http.RetrofitManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class KLineRepository : BaseRepository() {
    companion object {
        val instance = KLineRepository()
    }

    /**
     * 获取k线图数据
     */
    suspend fun getKLineData(type: String,granularity: Int): ResponseData<List<List<String>>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.createOKEXService().getKLineData(type, granularity)
        }

    /**
     * 获取深度数据
     */
    suspend fun getDepth(symbol: String): ResponseData<DepthBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.createOKEXService().getDepth(symbol)
        }

    /**
     * 获取成交数据
     */
    suspend fun getDeals(symbol: String): ResponseData<List<DealsBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.createOKEXService().getDeals(symbol)
        }

    /**
     * 获取简介数据
     */
    suspend fun getCurrencyDescribe(currency: String): ResponseData<CurrencyDescribe> =
        withContext(Dispatchers.IO) {
            RetrofitManager.createOKEXService().getCurrencyDescribe(currency)
        }
}